using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VWADESS
    {
        public DataRow Convert2WADESS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryWADESS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["WADMANDANT"] = " ".PadRight(2 ); 
         dwReturn["WADKUNDNR"] = " ".PadRight(8 ); 
         dwReturn["WADWERK"] = " ".PadRight(3 ); 
         dwReturn["WADABT"] = " ".PadRight(3 ); 
         dwReturn["WADART"] = " ".PadRight(20 ); 
         dwReturn["WADVAR"] = " ".PadRight(2 ); 
         dwReturn["WADDESS"] = " ".PadRight(10 ); 
         dwReturn["WADAENZL"] = " ".PadRight(0 ); 
         dwReturn["WADAENB"] = " ".PadRight(8 ); 
         dwReturn["WADAEND"] = " ".PadRight(0 ); 
         dwReturn["WADNEUB"] = " ".PadRight(8 ); 
         dwReturn["WADNEUD"] = " ".PadRight(0 ); 
         dwReturn["WADSPGRD"] = " ".PadRight(2 ); 
         dwReturn["WADZBRT"] = " ".PadRight(0 ); 
         dwReturn["WADTBRT"] = " ".PadRight(0 ); 
         dwReturn["WADDRAPPH"] = " ".PadRight(0 ); 
         dwReturn["WADDRAPPB"] = " ".PadRight(0 ); 
         dwReturn["WADBRTD"] = " ".PadRight(0 ); 
         dwReturn["WADARAPPH"] = " ".PadRight(0 ); 
         dwReturn["WADARAPPB"] = " ".PadRight(0 ); 
         dwReturn["WADABRT"] = " ".PadRight(0 ); 
         dwReturn["WADLRAPPH"] = " ".PadRight(0 ); 
         dwReturn["WADLRAPPB"] = " ".PadRight(0 ); 
         dwReturn["WADLBRT"] = " ".PadRight(0 ); 
         dwReturn["WADAUSRICH"] = " ".PadRight(1 ); 
         dwReturn["WADABSTL"] = " ".PadRight(0 ); 
         dwReturn["WADABSTR"] = " ".PadRight(0 ); 
         dwReturn["WADABSTBIS"] = " ".PadRight(18 ); 
         dwReturn["WADSEITEDR"] = " ".PadRight(1 ); 
         dwReturn["WADVORBEDR"] = " ".PadRight(3 ); 
         dwReturn["WADNACHBDR"] = " ".PadRight(3 ); 
         dwReturn["WADFILLER"] = " ".PadRight(54 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapWADESS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveWADESS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryWADESS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapWADESS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertWADESS(dwLocal, ITXDBVERSION);
            }
            UpdateWADESS(dwLocal);
        }
        public void InsertWADESS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO WADESS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryWADESS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM WADESS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM WADESS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "WADESS";
            Return = Result;
            return Return;
        }
        public void DeleteWADESS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM WADESS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateWADESS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE WADESS SET "
                    +"WADMANDANT= :WADMANDANT,"
                    +"WADKUNDNR= :WADKUNDNR,"
                    +"WADWERK= :WADWERK,"
                    +"WADABT= :WADABT,"
                    +"WADART= :WADART,"
                    +"WADVAR= :WADVAR,"
                    +"WADDESS= :WADDESS,"
                    +"WADAENZL= :WADAENZL,"
                    +"WADAENB= :WADAENB,"
                    +"WADAEND= :WADAEND,"
                    +"WADNEUB= :WADNEUB,"
                    +"WADNEUD= :WADNEUD,"
                    +"WADSPGRD= :WADSPGRD,"
                    +"WADZBRT= :WADZBRT,"
                    +"WADTBRT= :WADTBRT,"
                    +"WADDRAPPH= :WADDRAPPH,"
                    +"WADDRAPPB= :WADDRAPPB,"
                    +"WADBRTD= :WADBRTD,"
                    +"WADARAPPH= :WADARAPPH,"
                    +"WADARAPPB= :WADARAPPB,"
                    +"WADABRT= :WADABRT,"
                    +"WADLRAPPH= :WADLRAPPH,"
                    +"WADLRAPPB= :WADLRAPPB,"
                    +"WADLBRT= :WADLBRT,"
                    +"WADAUSRICH= :WADAUSRICH,"
                    +"WADABSTL= :WADABSTL,"
                    +"WADABSTR= :WADABSTR,"
                    +"WADABSTBIS= :WADABSTBIS,"
                    +"WADSEITEDR= :WADSEITEDR,"
                    +"WADVORBEDR= :WADVORBEDR,"
                    +"WADNACHBDR= :WADNACHBDR,"
                    +"WADFILLER= :WADFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("WADMANDANT", OracleType.NVarChar).Value = dwData["WADMANDANT"].ToString(); 
          or1.Parameters.Add("WADKUNDNR", OracleType.NVarChar).Value = dwData["WADKUNDNR"].ToString(); 
          or1.Parameters.Add("WADWERK", OracleType.NVarChar).Value = dwData["WADWERK"].ToString(); 
          or1.Parameters.Add("WADABT", OracleType.NVarChar).Value = dwData["WADABT"].ToString(); 
          or1.Parameters.Add("WADART", OracleType.NVarChar).Value = dwData["WADART"].ToString(); 
          or1.Parameters.Add("WADVAR", OracleType.NVarChar).Value = dwData["WADVAR"].ToString(); 
          or1.Parameters.Add("WADDESS", OracleType.NVarChar).Value = dwData["WADDESS"].ToString(); 
          or1.Parameters.Add("WADAENZL", OracleType.NVarChar).Value = dwData["WADAENZL"].ToString(); 
          or1.Parameters.Add("WADAENB", OracleType.NVarChar).Value = dwData["WADAENB"].ToString(); 
          or1.Parameters.Add("WADAEND", OracleType.NVarChar).Value = dwData["WADAEND"].ToString(); 
          or1.Parameters.Add("WADNEUB", OracleType.NVarChar).Value = dwData["WADNEUB"].ToString(); 
          or1.Parameters.Add("WADNEUD", OracleType.NVarChar).Value = dwData["WADNEUD"].ToString(); 
          or1.Parameters.Add("WADSPGRD", OracleType.NVarChar).Value = dwData["WADSPGRD"].ToString(); 
          or1.Parameters.Add("WADZBRT", OracleType.NVarChar).Value = dwData["WADZBRT"].ToString(); 
          or1.Parameters.Add("WADTBRT", OracleType.NVarChar).Value = dwData["WADTBRT"].ToString(); 
          or1.Parameters.Add("WADDRAPPH", OracleType.NVarChar).Value = dwData["WADDRAPPH"].ToString(); 
          or1.Parameters.Add("WADDRAPPB", OracleType.NVarChar).Value = dwData["WADDRAPPB"].ToString(); 
          or1.Parameters.Add("WADBRTD", OracleType.NVarChar).Value = dwData["WADBRTD"].ToString(); 
          or1.Parameters.Add("WADARAPPH", OracleType.NVarChar).Value = dwData["WADARAPPH"].ToString(); 
          or1.Parameters.Add("WADARAPPB", OracleType.NVarChar).Value = dwData["WADARAPPB"].ToString(); 
          or1.Parameters.Add("WADABRT", OracleType.NVarChar).Value = dwData["WADABRT"].ToString(); 
          or1.Parameters.Add("WADLRAPPH", OracleType.NVarChar).Value = dwData["WADLRAPPH"].ToString(); 
          or1.Parameters.Add("WADLRAPPB", OracleType.NVarChar).Value = dwData["WADLRAPPB"].ToString(); 
          or1.Parameters.Add("WADLBRT", OracleType.NVarChar).Value = dwData["WADLBRT"].ToString(); 
          or1.Parameters.Add("WADAUSRICH", OracleType.NVarChar).Value = dwData["WADAUSRICH"].ToString(); 
          or1.Parameters.Add("WADABSTL", OracleType.NVarChar).Value = dwData["WADABSTL"].ToString(); 
          or1.Parameters.Add("WADABSTR", OracleType.NVarChar).Value = dwData["WADABSTR"].ToString(); 
          or1.Parameters.Add("WADABSTBIS", OracleType.NVarChar).Value = dwData["WADABSTBIS"].ToString(); 
          or1.Parameters.Add("WADSEITEDR", OracleType.NVarChar).Value = dwData["WADSEITEDR"].ToString(); 
          or1.Parameters.Add("WADVORBEDR", OracleType.NVarChar).Value = dwData["WADVORBEDR"].ToString(); 
          or1.Parameters.Add("WADNACHBDR", OracleType.NVarChar).Value = dwData["WADNACHBDR"].ToString(); 
          or1.Parameters.Add("WADFILLER", OracleType.NVarChar).Value = dwData["WADFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
